<template>
  <div>
    <div class="goodreturn-mokuai">
      <!-- 头部 -->
      <div class="goodreturn-badges">
        <el-badge :value="count.one" class="goodreturn-item">
          <el-button size="small" @click="selectOne()">全部申请</el-button>
        </el-badge>
        <el-badge :value="count.two" class="item">
          <el-button size="small" @click="selectTwo()">待处理</el-button>
        </el-badge>
        <el-badge :value="count.three" class="item" type="primary">
          <el-button size="small" @click="selectThree()">退货中</el-button>
        </el-badge>
        <el-badge :value="count.four" class="item" type="warning">
          <el-button size="small" @click="selectFour()">已完成</el-button>
        </el-badge>
        <el-badge :value="count.five" class="item" type="warning">
          <el-button size="small" @click="selectFive()">已拒绝</el-button>
        </el-badge>
      </div>
      <!-- 筛选查找 -->
      <div class="goodreturn-index">
        <div class="goodreturn-index-top">
          <div class="goodreturn-name">
            <div class="goodreturn-name-font">
              <i class="el-icon-search"></i>
              筛选查询
            </div>
            <div class="goodreturn-name-right">
              <el-button @click="onSubmit()">查询结果</el-button>
              <el-button @click="onSubmitTwo()">高级检索</el-button>
            </div>
            <div class="goodreturn-name-right" @click="packUp">
              <i class="el-icon-arrow-up"></i>
              收起筛选
            </div>
          </div>
          <div class="goodreturn-content">
            <!-- 筛选条件 -->
            <div class="goodreturn-button-select-2" v-if="showPrise">
              <el-form :inline="true" :model="formInline" class="demo-form-inline">
                <el-form-item label="输入搜索:">
                  <el-input v-model="formInline.id" placeholder="服务单号" class="select-width-1"></el-input>
                </el-form-item>
                <el-form-item label="收货人手机号:">
                  <el-input
                    v-model="formInline.linkmanMobile"
                    placeholder="收货人手机号码"
                    class="select-width-1"
                  ></el-input>
                </el-form-item>
                <el-form-item label="申请时间:">
                  <el-date-picker v-model="formInline.applyTime" placeholder="请选择时间" type="date"></el-date-picker>
                </el-form-item>
              </el-form>
            </div>
          </div>
        </div>
      </div>

      <!-- 数据模块 -->
      <div class="goodreturn-index">
        <div class="goodreturn-index-top">
          <div class="goodreturn-name">
            <div class="goodreturn-name-font">
              <i class="el-icon-s-unfold"></i>
              数据列表
            </div>
            <div class="goodreturn-index-select">
              <div class="goodreturn-left goodreturn-index-select-button">
                <el-button @click="onExportData" size="small">导出数据</el-button>
              </div>
              <div class="goodreturn-left">
                <el-form :inline="true" :model="listLine" class="demo-form-inline" size="small">
                  <el-form-item label>
                    <el-select v-model="listLine.row" placeholder="显示条数" class="select-width-2">
                      <el-option label="10条" value="10"></el-option>
                      <el-option label="20条" value="20"></el-option>
                    </el-select>
                  </el-form-item>
                  <el-form-item label>
                    <el-select v-model="sort" placeholder="排序方式" class="select-width-2">
                      <el-option label="申请时间排序" value="0"></el-option>
                      <el-option label="处理时间排序" value="1"></el-option>
                      <el-option label="退款金额排序" value="2"></el-option>
                    </el-select>
                  </el-form-item>
                </el-form>
              </div>
            </div>
          </div>
          <div class="goodreturn-content">
            <!-- 数据列表 -->
            <div>
              <el-table
                ref="multipleTable"
                :data="tableData"
                tooltip-effect="dark"
                border
                style="width: 100%"
                @selection-change="handleSelectionChange"
              >
                <el-table-column type="selection" width="55" align="center"></el-table-column>
                <el-table-column label="服务单号" width="130" align="center">
                  <template slot-scope="scope">{{ scope.row.id }}</template>
                </el-table-column>
                <el-table-column prop="applyTime" label="申请时间" width="180" align="center">
                  <template slot-scope="scope">{{scope.row.applyTime}}</template>
                </el-table-column>
                <el-table-column prop="userAccount" label="用户账号" width="120" align="center">
                  <template slot-scope="scope">{{scope.row.userAccount}}</template>
                </el-table-column>
                <el-table-column prop="returnMoney" label="退款金额" align="center">
                  <template slot-scope="scope">{{scope.row.returnMoney}}</template>
                </el-table-column>
                <el-table-column prop="linkman" label="联系人" width="110" align="center">
                  <template slot-scope="scope">{{scope.row.linkman}}</template>
                </el-table-column>
                <el-table-column prop="status" label="申请状态" width="130" align="center">
                  <template slot-scope="scope">
                    <span v-if="scope.row.status == 0">待处理</span>
                    <span v-if="scope.row.status == 1">退货中</span>
                    <span v-if="scope.row.status == 2">已完成</span>
                    <span v-if="scope.row.status == 3">已拒绝</span>
                  </template>
                </el-table-column>
                <el-table-column prop="disposeTime" label="处理时间" width="180" align="center">
                  <template slot-scope="scope">{{scope.row.disposeTime}}</template>
                </el-table-column>
                <el-table-column fixed="right" label="操作" width="100" align="center">
                  <template slot-scope="scope">
                    <el-button
                      @click="handleClick(scope.$index, scope.row)"
                      type="text"
                      size="small"
                    >查看详情</el-button>
                  </template>
                </el-table-column>
              </el-table>
            </div>
            <!-- 页脚 -->
            <div class="goodreturn-paging">
              <!-- 批量操作 -->
              <div class="goodreturn-paging-leftlayout">
                <div class="opertation-block">
                  <!-- 全选需要设置方法目前只能操作0，1数据 -->
                  <el-button @click="toggleSelection([tableData[0], tableData[1]])" size="small">全选</el-button>
                </div>
                <div class="opertation-block">
                  <el-form :inline="false" :model="operation" class="demo-form-inline" size="small">
                    <el-form-item label>
                      <el-select
                        v-model="operation.opertationType"
                        placeholder="批量操作"
                        class="select-width-2"
                      >
                        <el-option label="删除(只能删除已拒绝的服务单)" value="0"></el-option>
                      </el-select>
                    </el-form-item>
                  </el-form>
                </div>
                <div class="opertation-block">
                  <el-button size="small" @click="remak">确定</el-button>
                </div>
              </div>
              <!-- 分页 -->
              <div class="goodreturn-paging-layout">
                <div class="block">
                  <span class="demonstration"></span>
                  <el-pagination
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page="currentPage4"
                    :page-sizes="pageSizes"
                    :page-size="pageSize"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="total"
                  ></el-pagination>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <!-- 高级检索 -->
    <div>
      <el-dialog title="高级检索" :visible.sync="dialogVisible" width="30%">
        <el-form :inline="true" :model="formInline" class="demo-form-inline" label-position="top">
          <el-form-item label="输入搜索">
            <el-input v-model="formInline.id" placeholder="服务单号" class="demo-input"></el-input>
          </el-form-item>
          <el-form-item label="收货人手机号:">
            <el-input v-model="formInline.linkman" placeholder="收货人手机号" class="demo-input"></el-input>
          </el-form-item>
          <el-form-item label="处理状态:">
            <el-select v-model="formInline.status" placeholder="全部" class="demo-input">
              <el-option label="待处理" value="0"></el-option>
              <el-option label="退货中" value="1"></el-option>
              <el-option label="已完成" value="2"></el-option>
              <el-option label="已拒绝" value="3"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="申请时间:">
            <el-date-picker
              v-model="formInline.applyTime"
              placeholder="请选择时间"
              type="date"
              style="width: 197px"
            ></el-date-picker>
          </el-form-item>
          <el-form-item label="操作人员:">
            <el-select v-model="formInline.adminId" placeholder="全部" class="demo-input">
              <el-option label="大哥" value="0"></el-option>
              <el-option label="大大" value="1"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="处理时间:">
            <el-date-picker
              v-model="formInline.disposeTime"
              placeholder="请选择时间"
              type="date"
              style="width: 197px"
            ></el-date-picker>
          </el-form-item>
          <el-form-item>
            <el-button @click="resetForms">重置</el-button>
            <el-button type="primary" @click="retives()">开始检索</el-button>
          </el-form-item>
        </el-form>
      </el-dialog>
    </div>
  </div>
</template>

<style>
/* 自定义 */
.demo-input {
  width: 197px;
}
.goodreturn-left {
  float: left;
}
.goodreturn-item {
  margin-top: 20px;
  margin-right: 40px;
}
.goodreturn-badges {
  height: 40px;
}
.select-width-1 {
  width: 200px;
}
.select-width-2 {
  width: 100px;
}
.goodreturn-mokuai {
  height: 1000px;
  background-color: rgb(249, 249, 249);
}
.goodreturn-index {
  width: 100%;
  margin: auto;
  background-color: rgb(255, 255, 255);
}
.goodreturn-index-top {
  margin-top: 30px;
}
.goodreturn-name {
  width: 100%;
  height: 50px;
  padding-top: 10px;
  background-color: rgb(240, 240, 240);
}
.goodreturn-name-font {
  height: 40px;
  line-height: 40px;
  float: left;
  margin-left: 20px;
  font-size: 14px;
}
.goodreturn-name-right {
  height: 40px;
  line-height: 40px;
  float: right;
  margin-right: 20px;
  font-size: 14px;
}
.goodreturn-index-select {
  width: 340px;
  float: right;
  margin-right: 20px;
  font-size: 14px;
  padding-top: 5px;
}
.goodreturn-index-select-button {
  margin-right: 20px;
}
.goodreturn-content {
  width: 100%;
}
.goodreturn-button-select-2 {
  height: 50px;
  padding-top: 10px;
  padding-left: 20px;
}

.opertation-block {
  display: inline-block;
  margin-left: 3px;
}
.goodreturn-paging {
  height: 50px;
  width: 100%;
  background-color: rgb(253, 253, 254);
}
.goodreturn-paging-leftlayout {
  float: left;
  margin-top: 7px;
}
.goodreturn-paging-layout {
  float: right;
  margin-top: 7px;
}
</style>

<script>
import reorderApi from "@/api/order/reorderlist";
import request from "@/utils/request";
export default {
  data() {
    return {
      // 计数
      count: {
        one: "",
        two: "",
        three: "",
        four: "",
        five: "",
        six: ""
      },

      //分页
      pageSize: 2,
      pageSizes: [2, 3, 4, 5, 10, 25, 50, 100],
      total: 5,
      currentPage4: 1,
      sort: 0,

      //   弹出框
      formInline: {
        id: null,
        linkman: null,
        linkmanMobile: null,
        applyTime: null,
        adminId: null,
        disposeTime: null
      },
      dialogVisible: false,
      // 隐藏
      showPrise: true,
      //开起筛选
      selectrue: true,

      listLine: {
        row: "",
        sort: ""
      },
      operation: {
        opertationType: ""
      },
      // 列表数据
      tableData: [],

      multipleSelection: []
      // 分页
    };
  },
  //排序方式监听触发
  watch: {
    sort(val1, newval) {
      console.log(val1);
      console.log(newval);
      if (this.selectrue == true) {
        this.inDataTwo(
          this.currentPage4,
          this.pageSize,
          val1,
          this.formInline.id,
          this.formInline.linkman,
          this.formInline.linkmanMobile,
          this.formInline.applyTime,
          this.formInline.status,
          this.formInline.disposeTime,
          this.formInline.adminId
        );
      } else {
        this.inData(this.currentPage4, this.pageSize, val1);
      }
    }
  },

  methods: {
    // 时间转化
    parseTime(str) {
      if ((str + "").indexOf("-") != -1) {
        str = str.replace(new RegExp(/-/gm), "/");
      }
      let d = new Date(str);
      let newDateYear = d.getFullYear();
      let newDateMonth =
        d.getMonth() + 1 < 10 ? "0" + (d.getMonth() + 1) : d.getMonth() + 1;
      let newDateDay =
        d.getDate() + "" < 10 ? "0" + d.getDate() + "" : d.getDate() + "";
      return newDateYear + "-" + newDateMonth + "-" + newDateDay;
    },

    // 时间转化
    parseTime1(str) {
      if ((str + "").indexOf("-") != -1) {
        str = str.replace(new RegExp(/-/gm), "/");
      }
      let d = new Date(str);
      let newDateYear = d.getFullYear();
      let newDateMonth =
        d.getMonth() + 1 < 10 ? "0" + (d.getMonth() + 1) : d.getMonth() + 1;
      let newDateDay =
        d.getDate() + "" < 10 ? "0" + d.getDate() + "" : d.getDate() + "";
      return newDateYear + "-" + newDateMonth + "-" + newDateDay;
    },

    //   导出数据
    onExportData() {
      console.log("导出数据");
    },
    // 数据列表
    toggleSelection() {
      if (this.tableData) {
        this.tableData.forEach(row => {
          this.$refs.multipleTable.toggleRowSelection(row);
        });
      } else {
        this.$refs.multipleTable.clearSelection();
      }
    },

    handleSelectionChange(val) {
      this.multipleSelection = [];
      val.forEach(v => {
        this.multipleSelection[this.multipleSelection.length] = v.id;
      });
    },

    //批量删除
    remak() {
      this.$confirm("是否删除" + "提示", {
        type: "warning"
      }).then(() => {
        console.log(this.multipleSelection);
        reorderApi.getAllDel(this.multipleSelection).then(response => {
          const psa = response.data;
          console.log(response);
          if (psa.code == 200) {
            this.inData(this.currentPage4, this.pageSize, this.sort);
          } else {
            this.$message({
              message: psa.message,
              type: "warning"
            });
          }
        });
      });
    },

    //跳转页面
    handleClick(index, row) {
      this.$router.push({
        path: "/order/goodsReturnBill",
        query: { id: row.id, orderId: row.orderId }
      });
    },

    // 分页
    handleSizeChange(val) {
      this.pageSize = val;
      console.log(`每页 ${this.pageSize} 条`);
      if (this.selectrue == true) {
        this.inDataTwo(
          this.currentPage4,
          this.pageSize,
          this.sort,
          this.formInline.id,
          this.formInline.linkman,
          this.formInline.linkmanMobile,
          this.formInline.applyTime,
          this.formInline.status,
          this.formInline.disposeTime,
          this.formInline.adminId
        );
      } else {
        this.inData(this.currentPage4, this.pageSize, this.sort);
      }
    },

    handleCurrentChange(val) {
      this.currentPage4 = val;
      console.log(`当前页: ${this.currentPage4}`);
      if (this.selectrue == true) {
        this.inDataTwo(
          this.currentPage4,
          this.pageSize,
          this.sort,
          this.formInline.id,
          this.formInline.linkman,
          this.formInline.linkmanMobile,
          this.formInline.applyTime,
          this.formInline.status,
          this.formInline.disposeTime,
          this.formInline.adminId
        );
      } else {
        this.inData(this.currentPage4, this.pageSize, this.sort);
      }
    },

    inData(pageNum, pageSize, sort) {
      reorderApi.getPageList(pageNum, pageSize, sort).then(Response => {
        console.log(Response);
        this.tableData = Response.data.data.list;
        this.total = Response.data.data.total;
      });
    },

    //筛选条件
    inDataTwo(
      pageNum,
      pageSize,
      sort,
      id,
      linkman,
      linkmanMobile,
      applyTime,
      status,
      disposeTime,
      adminId
    ) {
      if (
        id != null ||
        linkman != null ||
        linkmanMobile != null ||
        applyTime != null ||
        status != null ||
        disposeTime != null ||
        adminId != null
      ) {
        this.selectrue = true;
      } else {
        this.selectrue = false;
      }
      console.log("筛选" + this.selectrue);
      // 转化时间

      if (applyTime != null) {
        var time = this.parseTime(applyTime);
      } else {
        var time = applyTime;
      }

      if (disposeTime != null) {
        var time1 = this.parseTime1(disposeTime);
      } else {
        var time1 = disposeTime;
      }

      reorderApi
        .getListByOrder(
          pageNum,
          pageSize,
          sort,
          id,
          linkman,
          linkmanMobile,
          time,
          status,
          time1,
          adminId
        )
        .then(Response => {
          console.log(Response);
          // var data=JSON.parse(JSON.stringify( ))
          this.tableData = Response.data.data.list;
          this.total = Response.data.data.total;
        });
    },

    onSubmit() {
      this.currentPage4 = 1;
      this.pageSize = 2;
      console.log(this.formInline);
      this.inDataTwo(
        this.currentPage4,
        this.pageSize,
        this.sort,
        this.formInline.id,
        this.formInline.linkman,
        this.formInline.linkmanMobile,
        this.formInline.applyTime
      );
    },

    resetForms() {
      this.formInline.id = null;
      this.formInline.linkmanMobile = null;
      this.formInline.applyTime = null;
      this.formInline.status = null;
      this.formInline.disposeTime = null;
      this.formInline.adminId = null;
    },

    retives() {
      (this.currentPage4 = 1),
        (this.pageSize = 2),
        this.inDataTwo(
          this.currentPage4,
          this.pageSize,
          this.sort,
          this.formInline.id,
          this.formInline.linkman,
          this.formInline.linkmanMobile,
          this.formInline.applyTime,
          this.formInline.status,
          this.formInline.disposeTime,
          this.formInline.adminId
        );
      this.dialogVisible = false;
    },

    // 弹出框
    onSubmitTwo() {
      console.log("弹出框!");
      this.dialogVisible = true;
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    // 点击显示和隐藏
    packUp: function() {
      this.showPrise = !this.showPrise;
    },
    countData(status) {
      reorderApi.getAllObj(status).then(Response => {
        console.log(Response);
        if (status == null) {
          this.count.one = Response.data.data;
        }
        if (status == 0) {
          this.count.two = Response.data.data;
        }
        if (status == 1) {
          this.count.three = Response.data.data;
        }
        if (status == 2) {
          this.count.four = Response.data.data;
        }
        if (status == 3) {
          this.count.five = Response.data.data;
        }
      });
    }
  },

  mounted() {
    this.inData(this.currentPage4, this.pageSize, this.sort);
    this.countData(null);
    this.countData(0);
    this.countData(1);
    this.countData(2);
    this.countData(3);
  }
};
</script>
